package oa.hleast.xswl.controller.app;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.enums.QueryModeEnum;
import oa.hleast.common.result.Result;
import oa.hleast.xswl.pojo.domain.StorePayInfo;
import oa.hleast.xswl.service.store.StorePayInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "【移动端】商家支付信息表")
@RestController("AppStorePayInfoController")
@RequestMapping("/api.app/v1/storePayInfos")
@Slf4j
@AllArgsConstructor
public class StorePayInfoController {

    private StorePayInfoService storePayInfoService;

    @ApiOperation(value = "列表分页", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryMode", value = "查询模式", paramType = "query", dataTypeClass = QueryModeEnum.class, dataType = "QueryModeEnum"),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataTypeClass = Long.class, dataType = "Long"),
            @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataTypeClass = Long.class, dataType = "Long")
    })
    @GetMapping
    public Result list(
            String queryMode,
            Integer page,
            Integer limit,
            String name) {
        QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode);
        switch (queryModeEnum) {
            default:
                LambdaQueryWrapper<StorePayInfo> queryWrapper = new LambdaQueryWrapper<StorePayInfo>()
                        .orderByDesc(StorePayInfo::getGmtModified)
                        .orderByDesc(StorePayInfo::getGmtCreate);

                Page<StorePayInfo> result = storePayInfoService.page(new Page<>(page, limit), queryWrapper);
                return Result.success(result.getRecords(), result.getTotal());
        }
    }

    @ApiOperation(value = "详情", httpMethod = "GET")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataTypeClass = Long.class, dataType = "Long")
    @GetMapping("/{id}")
    public Result detail(@PathVariable Long id) {
        return Result.success(storePayInfoService.getById(id));
    }

}
